package com.hainatong.jcmvvmbase.mainhome;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.gyf.immersionbar.ImmersionBar;
import com.hainatong.jcmvvmbase.LazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.ActivityMainHomeBinding;
import com.hainatong.jcmvvmbase.mainhome.adapter.HomeFragmentPagerAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.TabEntity;
import com.hainatong.jcmvvmbase.mainhome.fragment.MessageFragment;
import com.hainatong.jcmvvmbase.mainhome.fragment.UserFragment;
import com.hainatong.jcmvvmbase.mainhome.fragment.WelcomeFragment;
import com.hainatong.jcmvvmbase.widget.FireManeuverDialog;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.base.NoViewModel;

import android.content.Context;
import android.content.Intent;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.hainatong.mvvmbase.utils.StatusBarUtils;

public class MainHomeActivity extends BaseMvvmActivity<ActivityMainHomeBinding, NoViewModel>
{

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private List<Fragment> fragmentList;
    private HomeFragmentPagerAdapter vpAdapter;
    private FireManeuverDialog maneuverDialog;

    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_main_home;
    }

    @Override
    protected int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void initView()
    {
        ImmersionBar.with(this).init();
        maneuverDialog = new FireManeuverDialog(this);


        mTabEntities.add(new TabEntity(getString( R.string.first_page_tag ), R.mipmap.ic_tab_home_select, R.mipmap.ic_tab_home_unselect));
        mTabEntities.add(new TabEntity(getString( R.string.msg_page_tag ), R.mipmap.ic_tab_msg_select, R.mipmap.ic_tab_msg_unselect));
        mTabEntities.add(new TabEntity(getString( R.string.me_page_tag ), R.mipmap.ic_tab_me_select, R.mipmap.ic_tab_me_unselect));
        fragmentList = new ArrayList<>();
        fragmentList.add( new WelcomeFragment());
        fragmentList.add( new MessageFragment());
        fragmentList.add( new UserFragment());

        vpAdapter = new HomeFragmentPagerAdapter(getSupportFragmentManager(),fragmentList);
        viewDataBinding.vpHome.setAdapter( vpAdapter );
        viewDataBinding.vpHome.setOffscreenPageLimit(3);
        viewDataBinding.comTl.setTabData( mTabEntities );
        viewDataBinding.comTl.setOnTabSelectListener(new OnTabSelectListener() {
           @Override
           public void onTabSelect(int position)
           {
               viewDataBinding.vpHome.setCurrentItem( position );

               // 设置状态栏为白底黑字
               StatusBarUtils.setStatusBarDarkFont(MainHomeActivity.this, true);

               if( position == 2 )
               {
                   maneuverDialog.show();
               }
           }

           @Override
           public void onTabReselect(int position)
           {
           }
       });
        viewDataBinding.vpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                viewDataBinding.comTl.setCurrentTab( position );

                // 设置状态栏为白底黑字
                StatusBarUtils.setStatusBarDarkFont(MainHomeActivity.this, true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData()
    {
        viewDataBinding.comTl.showMsg(1,0);
    }

    @Override
    protected void onRetryBtnClick()
    {
    }

    public static void start(Context context)
    {
        context.startActivity(new Intent(  context,MainHomeActivity.class  ));
    }
}
